import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.junit.Test;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

public class test {
    @Test
    public void test01() throws IOException {
        //设置velocity资源加载器
        Properties prop = new Properties();
        prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        Velocity.init(prop);
        //创建Velocity容器
        VelocityContext context = new VelocityContext();
        context.put("name", "dayu");
        //加载模板
        Template tpl = Velocity.getTemplate("vms/struct.vm", "UTF-8");
        FileWriter fw = new FileWriter("E:\\Desktop\\java-project\\utools\\CTypesCodeGeneration\\src\\main\\resources\\out\\template01.txt");
        //合并数据到模板
        tpl.merge(context, fw);
        //释放资源
        fw.close();
    }
}
